ALMaSS  1.0
The Animal, Landscape and Man Simulation System
SkTerritories Class Reference

#include <skylarks_all.h>

Public Member Functions

void Tick (void)
 
void EvaluateAllTerritories (void)
 
void PreCachePoly (int a_poly)
 
double PrePoly2Qual (int a_poly)
 
double PrePolyNQual (int a_poly, int *a_good_polys)
 
void PreProcessLandscape2 (Landscape *L)
 
void ClaimGrid (int x, int y, int range)
 
void UpdateQuality ()
 
bool IsGridPositionValid (int &x, int &y, int range)
 
bool IsExtGridPositionValid (int &x, int &y, int range)
 
int IsValid (int nx, int ny)
 
void GetTerritoriesByDistance (int nx, int ny, vector< APoint > *alist)
 
int Supply_quality (int ref)
 
int Supply_x (int ref)
 
int Supply_y (int ref)
 
int Supply_size (int ref)
 
skTTerritorySupply_terr (int ref)
 
void RemoveFemale (int ref)
 
void RemoveMale (int ref)
 
void Split (int ref)
 
Skylark_MaleSupply_Owner (int ref)
 
Skylark_FemaleSupply_F_Owner (int ref)
 
void Occupy (int ref, Skylark_Male *Male)
 
void FemaleOccupy (int ref, Skylark_Female *Female)
 
double EvaluateHabitatN (skTTerritory *a_terr)
 
int SupplyNoTerritories ()
 
int SupplyNoMaleOccupied ()
 
int SupplyNoFemaleOccupied ()
 
bool SupplyIsNestValid (int ref)
 
APoint SupplyNestPosition (int ref)
 
 SkTerritories (Landscape *L)
 
 ~SkTerritories ()
 

Public Attributes

int PolyRefData [2500]
 
int PolySizeData [2500]
 
double PolyHeightData [2500]
 
TTypesOfLandscapeElement PolyTypeData [2500]
 
LandscapeTheLandscape
 

Private Member Functions

int EvaluateHabitatSquare (int xmin, int xmax, int ymin, int ymax, int NoPolygons)
 
int PreMakeForIterator (int a_min_incl, int a_max_excl, int *a_iter, int a_norm_max_excl)
 
void PreFillTerrPolyLists (skTTerritory *a_terr)
 
void PreFillQualGrid (void)
 
void PreEvaluateQualGrid (SkQualGrid *a_grid, int a_x, int a_y, int a_width, int a_height)
 
void PreFillQualCache (void)
 
int PreEvaluateHabitat (int a_x, int a_y, int a_range_x, int a_range_y)
 
int PreEvaluateHabitatStripX (int a_x, int a_y, int a_range_x)
 
int PreEvaluateHabitatStripY (int a_x, int a_y, int a_range_x)
 
void DumpMapGraphics (const char *a_filename, Landscape *a_map)
 

Private Attributes

skTTerritoryTerritories [400000]
 
int NoTerritories
 
int SimW
 
int SimH
 
bool * Grid
 
int m_sim_w_div_10
 
int m_sim_h_div_10
 
int m_qual_grid_signal
 
SkQualGrid ** m_qual_grid
 
int m_hash_size
 
int * m_poly_seen
 
int * m_poly_size
 
double * m_qual_cache
 
bool m_qual_cache_filled
 
int m_for_iter_x [1000]
 
int m_for_iter_y [1000]
 

Constructor & Destructor Documentation

◆ SkTerritories()

SkTerritories::SkTerritories ( Landscape L)
1386  {
1387  TheLandscape = L;
1388  NoTerritories = 0; // must be set to zero otherwise will try to delete
1389  // non-existant territories on first call of PreProcessLandscape2()
1390  SimW = L->SupplySimAreaWidth();
1391  SimH = L->SupplySimAreaHeight();
1392  m_sim_w_div_10 = SimW / 10;
1393  m_sim_h_div_10 = SimH / 10;
1394  Grid = new bool[m_sim_w_div_10 * m_sim_h_div_10];
1395  m_qual_grid_signal = -1;
1396 }
int SupplySimAreaHeight(void)
Definition: landscape.h:1637
int SupplySimAreaWidth(void)
Definition: landscape.h:1632
int SimW
Definition: skylarks_all.h:348
int SimH
Definition: skylarks_all.h:348
int m_sim_w_div_10
Definition: skylarks_all.h:355
int NoTerritories
Definition: skylarks_all.h:347
int m_sim_h_div_10
Definition: skylarks_all.h:355
bool * Grid
Definition: skylarks_all.h:349
Landscape * TheLandscape
Definition: skylarks_all.h:402
int m_qual_grid_signal
Definition: skylarks_all.h:356

References Grid, m_qual_grid_signal, m_sim_h_div_10, m_sim_w_div_10, NoTerritories, SimH, SimW, Landscape::SupplySimAreaHeight(), Landscape::SupplySimAreaWidth(), and TheLandscape.

◆ ~SkTerritories()

SkTerritories::~SkTerritories ( )
1401  {
1402  for ( int i = 0; i < NoTerritories; i++ ) delete Territories[ i ];
1403  free( m_poly_seen );
1404  free( m_poly_size );
1405  free( m_qual_cache );
1406 
1407  for ( int i = 0; i < m_sim_w_div_10 * m_sim_h_div_10; i++ ) {
1408  delete m_qual_grid[ i ];
1409  }
1410  free( m_qual_grid );
1411 }
double * m_qual_cache
Definition: skylarks_all.h:365
int * m_poly_size
Definition: skylarks_all.h:362
SkQualGrid ** m_qual_grid
Definition: skylarks_all.h:357
int * m_poly_seen
Definition: skylarks_all.h:361
skTTerritory * Territories[400000]
Definition: skylarks_all.h:346

References m_poly_seen, m_poly_size, m_qual_cache, m_qual_grid, m_sim_h_div_10, m_sim_w_div_10, NoTerritories, and Territories.

Member Function Documentation

◆ ClaimGrid()

void SkTerritories::ClaimGrid ( int  x,
int  y,
int  range 
)
2331  {
2332  int l_max_x = x + range;
2333  if ( l_max_x > m_sim_w_div_10 )
2334  l_max_x = m_sim_w_div_10;
2335 
2336  int l_max_y = y + range;
2337  if ( l_max_y > m_sim_h_div_10 )
2338  l_max_y = m_sim_h_div_10;
2339 
2340  for ( int i = x; i < l_max_x; i++ ) {
2341  for ( int j = y; j < l_max_y; j++ ) {
2342  Grid[i + j * m_sim_w_div_10] = true;
2343  }
2344  }
2345 }

References Grid, m_sim_h_div_10, and m_sim_w_div_10.

Referenced by PreProcessLandscape2().

◆ DumpMapGraphics()

void SkTerritories::DumpMapGraphics ( const char *  a_filename,
Landscape a_map 
)
private
1477 {
1478  int l_width = a_map->SupplySimAreaWidth();
1479  int l_height = a_map->SupplySimAreaHeight();
1480  unsigned int linesize = l_width * 3;
1481  unsigned char * frame_buffer = ( unsigned char * ) malloc( sizeof( unsigned char ) * linesize * l_height );
1482 
1483  FILE * l_file;
1484 
1485  if ( frame_buffer == NULL ) {
1486  g_msg->Warn( WARN_FILE, "SkTerritories::DumpMapGraphics(): Out of memory!", "" );
1487  exit( 1 );
1488  }
1489 
1490  for ( int y = 0, i = 0; y < l_height; y++ ) {
1491  for ( int x = 0; x < l_width; x++ ) {
1492  int eletype = ( int )a_map->SupplyElementType( x, y );
1493  int localcolor = 16777215/eletype;
1494 
1495  if ( eletype == ( int )tole_Field ) {
1496  int category;
1497  double hei = a_map->SupplyVegHeight( x, y );
1498  if ( hei > 50.0 ) category = 0; else
1499  category = ( int )( 200.0 - ( hei * 4.0 ) );
1500  localcolor = ( ( category * 65536 ) + 65535 );
1501  }
1502 
1503  frame_buffer[ i++ ] = (unsigned char)(localcolor & 0xff);
1504  frame_buffer[ i++ ] = (unsigned char)(( localcolor >> 8 ) & 0xff);
1505  frame_buffer[ i++ ] = (unsigned char) (( localcolor >> 16 ) & 0xff);
1506  }
1507  }
1508 
1509  for ( int i = 0; i < NoTerritories; i++ ) {
1510  int l_x = Territories[ i ]->m_Location_x;
1511  int l_y = Territories[ i ]->m_Location_y;
1512  int l_s = Territories[ i ]->Size;
1513  // Horizontal lines of territory bounding box.
1514  for ( int x = l_x; x < l_x + l_s; x++ ) {
1515  int y = l_y;
1516  if ( x >= 0 && x < l_width && y >= 0 && y < l_height ) {
1517  int pixel_p = x * 3 + linesize * y;
1518  frame_buffer[ pixel_p++ ] = 200;
1519  frame_buffer[ pixel_p++ ] = 0;
1520  frame_buffer[ pixel_p ] = 0;
1521  }
1522  y = l_y + l_s - 1;
1523  if ( x >= 0 && x < l_width && y >= 0 && y < l_height ) {
1524  int pixel_p = x * 3 + linesize * y;
1525  frame_buffer[ pixel_p++ ] = 200;
1526  frame_buffer[ pixel_p++ ] = 0;
1527  frame_buffer[ pixel_p ] = 0;
1528  }
1529  }
1530  for ( int y = l_y; y < l_y + l_s; y++ ) {
1531  int x = l_x;
1532  if ( x >= 0 && x < l_width && y >= 0 && y < l_height ) {
1533  int pixel_p = x * 3 + linesize * y;
1534  frame_buffer[ pixel_p++ ] = 200;
1535  frame_buffer[ pixel_p++ ] = 0;
1536  frame_buffer[ pixel_p ] = 0;
1537  }
1538  x = l_x + l_s - 1;
1539  if ( x >= 0 && x < l_width && y >= 0 && y < l_height ) {
1540  int pixel_p = x * 3 + linesize * y;
1541  frame_buffer[ pixel_p++ ] = 200;
1542  frame_buffer[ pixel_p++ ] = 0;
1543  frame_buffer[ pixel_p ] = 0;
1544  }
1545  }
1546  }
1547 
1548  l_file = fopen(a_filename, "w" );
1549  if ( !l_file ) {
1550  g_msg->Warn( WARN_FILE, "SkTerritories::DumpMapGraphics(): ""Unable to open file for writing: %s\n", a_filename );
1551  exit( 1 );
1552  }
1553 
1554  fprintf( l_file, "P6\n%d %d %d\n", l_width, l_height, 255 );
1555  fwrite( frame_buffer, sizeof( unsigned char ), linesize * l_height, l_file );
1556  fclose( l_file );
1557 
1558  free( frame_buffer );
1559 }
double SupplyVegHeight(int a_polyref)
Definition: landscape.h:936
TTypesOfLandscapeElement SupplyElementType(int a_polyref)
Definition: landscape.h:1110
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
int m_Location_y
Definition: skylarks_all.h:283
int m_Location_x
Definition: skylarks_all.h:282
int Size
Definition: skylarks_all.h:281
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
@ WARN_FILE
Definition: maperrormsg.h:37
@ tole_Field
Definition: tole_declaration.h:43

References g_msg, skTTerritory::m_Location_x, skTTerritory::m_Location_y, NoTerritories, skTTerritory::Size, Landscape::SupplyElementType(), Landscape::SupplySimAreaHeight(), Landscape::SupplySimAreaWidth(), Landscape::SupplyVegHeight(), Territories, tole_Field, MapErrorMsg::Warn(), and WARN_FILE.

◆ EvaluateAllTerritories()

void SkTerritories::EvaluateAllTerritories ( void  )
2240 {
2241  for ( int i = 0; i < NoTerritories; i++ ) {
2243  }
2244 }
double EvaluateHabitatN(skTTerritory *a_terr)
Definition: skylarks_all.cpp:2246

References EvaluateHabitatN(), NoTerritories, and Territories.

Referenced by Skylark_Population_Manager::DoFirst().

◆ EvaluateHabitatN()

double SkTerritories::EvaluateHabitatN ( skTTerritory a_terr)
2246  {
2247  //a_good_polys = 0;
2248  int a_area_polys = 0;
2249  int l_polygons = (int) a_terr->m_polys.size();
2250  double l_qual = 0.0;
2251 
2252  if ( l_polygons > 2500 ) {
2253  g_land->Warn( "SkTerritories::EvaluateHabitat1(): - Polygons > 2500", "" );
2254  exit( 1 );
2255  }
2256 
2257  for ( int i = 0; i < l_polygons; i++ ) {
2258  int l_poly = a_terr->m_polys[ i ];
2259  l_qual += ( double )( a_terr->m_sizes[ i ] ) * PrePolyNQual( l_poly, 0 );
2260  //l_qual += ( double )( a_terr->m_sizes[ i ] ) * PrePoly2Qual( l_poly );
2261  a_area_polys += a_terr->m_sizes[ i ];
2262  }
2263 
2264  l_qual *= ( a_terr->m_competitionscaler); //* a_terr->GetHeterogeneity());
2265  // Update territory quality
2266  a_terr->SetQuality((int) l_qual);
2267  // return the quality to calling method
2268  return l_qual;
2269 }
void Warn(std::string a_msg1, std::string a_msg2)
Definition: landscape.h:1579
double PrePolyNQual(int a_poly, int *a_good_polys)
Definition: skylarks_all.cpp:1768
vector< int > m_polys
Definition: skylarks_all.h:265
double m_competitionscaler
Definition: skylarks_all.h:276
void SetQuality(int a_qual)
Definition: skylarks_all.h:285
vector< int > m_sizes
Definition: skylarks_all.h:266
Landscape * g_land
This pointer provides access the to landscape module.
Definition: skylarks_all.cpp:49

References g_land, skTTerritory::m_competitionscaler, skTTerritory::m_polys, skTTerritory::m_sizes, PrePolyNQual(), skTTerritory::SetQuality(), and Landscape::Warn().

Referenced by EvaluateAllTerritories().

◆ EvaluateHabitatSquare()

int SkTerritories::EvaluateHabitatSquare ( int  xmin,
int  xmax,
int  ymin,
int  ymax,
int  NoPolygons 
)
private

◆ FemaleOccupy()

void SkTerritories::FemaleOccupy ( int  ref,
Skylark_Female Female 
)
2392  {
2393  Territories[ ref ]->F_Owner = Female;
2394 }
Skylark_Female * F_Owner
Definition: skylarks_all.h:287

References skTTerritory::F_Owner, and Territories.

Referenced by Skylark_Female::EstablishTerritory(), and Skylark_Male::OnReHouse().

◆ GetTerritoriesByDistance()

void SkTerritories::GetTerritoriesByDistance ( int  nx,
int  ny,
vector< APoint > *  alist 
)
2364  {
2365  int dist=0;
2366 // alist->resize(NoTerritories);
2367  APoint p;
2368  for ( int i = 0; i < NoTerritories; i++ ) {
2369  dist = abs(Territories[ i ]->m_Location_x-nx);
2370  dist += abs(Territories[ i ]->m_Location_y-ny);
2371  p.m_x = i;
2372  p.m_y = dist;
2373  alist->push_back(p);
2374  }
2375  sort(alist->begin(), alist->end(), CompareDist);
2376 }
A simple class defining an x,y coordinate set.
Definition: ALMaSS_Setup.h:53
int m_y
Definition: ALMaSS_Setup.h:56
int m_x
Definition: ALMaSS_Setup.h:55
bool CompareDist(APoint i, APoint j)
Definition: skylarks_all.cpp:159

References CompareDist(), APoint::m_x, APoint::m_y, NoTerritories, and Territories.

Referenced by Skylark_Male::OnEvicted(), and Skylark_Male::st_Arriving().

◆ IsExtGridPositionValid()

bool SkTerritories::IsExtGridPositionValid ( int &  x,
int &  y,
int  range 
)
2296  {
2297  // The commented out code **CJT** below could be used if we want
2298  // to invalidate the whole area up to the point where we hit problems
2299  // However, this will lead to large territory-less holes in the
2300  // landscape
2301 
2302  int l_max_x = x + range;
2303  if ( l_max_x > m_sim_w_div_10 ) {
2304  // l_max_x = m_sim_w_div_10;
2305  return false;
2306  }
2307 
2308  int l_max_y = y + range;
2309  if ( l_max_y > m_sim_h_div_10 ) {
2310  //l_max_y = m_sim_h_div_10;
2311  return false;
2312  }
2313 
2314  //Needs only to check the left most column and bottom row
2315  // The leftmost column
2316  for ( int j = y; j < l_max_y; j++ ) {
2317  if (Grid[x + j * m_sim_w_div_10]) {
2318  return false;
2319  }
2320  }
2321  // The bottom row
2322  for ( int i = x; i < l_max_x; i++ ) {
2323  if (Grid[i + y * m_sim_w_div_10]) {
2324  return false;
2325  }
2326  }
2327  // All OK
2328  return true;
2329 }

References Grid, m_sim_h_div_10, and m_sim_w_div_10.

Referenced by PreProcessLandscape2().

◆ IsGridPositionValid()

bool SkTerritories::IsGridPositionValid ( int &  x,
int &  y,
int  range 
)
2272  {
2273  int l_max_x = x + range;
2274  if ( l_max_x > m_sim_w_div_10 ) {
2275  //l_max_x = m_sim_w_div_10;
2276  return false;
2277  }
2278 
2279  int l_max_y = y + range;
2280  if ( l_max_y > m_sim_h_div_10 ) {
2281  //l_max_y = m_sim_h_div_10;
2282  return false;
2283  }
2284 
2285  for ( int i = x; i < l_max_x; i++ ) {
2286  for ( int j = y; j < l_max_y; j++ ) {
2287  if (Grid[i + j * m_sim_w_div_10]) {
2288  return false;
2289  }
2290  }
2291  }
2292  // No occupied squares found so
2293  return true;
2294 }

References Grid, m_sim_h_div_10, and m_sim_w_div_10.

Referenced by PreProcessLandscape2().

◆ IsValid()

int SkTerritories::IsValid ( int  nx,
int  ny 
)
2350  {
2351  int found = -1;
2352  for ( int i = 0; i < NoTerritories; i++ ) {
2353  if ( ( Territories[ i ]->m_Location_x <= nx ) && ( Territories[ i ]->m_Location_x + Territories[ i ]->Size > nx )
2354  && ( Territories[ i ]->m_Location_y <= ny ) && ( Territories[ i ]->m_Location_y + Territories[ i ]->Size > ny ) ) {
2355  found = i;
2356  break;
2357  }
2358  }
2359  return found;
2360 }

References NoTerritories, and Territories.

◆ Occupy()

void SkTerritories::Occupy ( int  ref,
Skylark_Male Male 
)
2385  {
2386  Territories[ ref ]->Owner = Male;
2387 }
Skylark_Male * Owner
Definition: skylarks_all.h:286

References skTTerritory::Owner, and Territories.

Referenced by Skylark_Male::EstablishingATerritory().

◆ PreCachePoly()

void SkTerritories::PreCachePoly ( int  a_poly)
1564 {
1565  m_qual_cache[a_poly] = PrePoly2Qual(a_poly);
1566 }
double PrePoly2Qual(int a_poly)
Definition: skylarks_all.cpp:1642

References m_qual_cache, and PrePoly2Qual().

Referenced by Landscape::SkylarkEvaluation().

◆ PreEvaluateHabitat()

int SkTerritories::PreEvaluateHabitat ( int  a_x,
int  a_y,
int  a_range_x,
int  a_range_y 
)
inlineprivate
1957  {
1958  double l_qual = 0.0;
1959 
1960  int l_max_x = a_x + a_range_x;
1961  int l_max_y = a_y + a_range_y;
1962  if ( l_max_x > m_sim_w_div_10 )
1963  l_max_x = m_sim_w_div_10;
1964  if ( l_max_y > m_sim_h_div_10 )
1965  l_max_y = m_sim_h_div_10;
1966 
1967  for ( int x = a_x; x < l_max_x; x++ ) {
1968  for ( int y = a_y; y < l_max_y; y++ ) {
1969  int l_i = x + y * m_sim_w_div_10;
1970  l_qual += m_qual_grid[ l_i ]->m_qual;
1971  }
1972  }
1973  return ( int )l_qual;
1974 }
double m_qual
Definition: skylarks_all.h:326

References SkQualGrid::m_qual, m_qual_grid, m_sim_h_div_10, and m_sim_w_div_10.

Referenced by PreProcessLandscape2().

◆ PreEvaluateHabitatStripX()

int SkTerritories::PreEvaluateHabitatStripX ( int  a_x,
int  a_y,
int  a_range_x 
)
inlineprivate
1976  {
1977  double l_qual = 0.0;
1978  int l_y_fixed = a_y * m_sim_w_div_10;
1979 
1980  int l_max_x = a_x + a_range_x;
1981  if ( l_max_x > m_sim_w_div_10 )
1982  l_max_x = m_sim_w_div_10;
1983 
1984  for ( int x = a_x; x < l_max_x; x++ ) {
1985  int l_i = x + l_y_fixed;
1986  l_qual+=m_qual_grid[ l_i ]->m_qual;
1987 /*
1988  int l_gmax = (int)m_qual_grid[ l_i ]->m_polys.size();
1989  for ( int g = 0; g < l_gmax; g++ ) {
1990  l_qual += ( double )( m_qual_grid[ l_i ]->m_sizes[ g ] ) * m_qual_cache[ m_qual_grid[ l_i ]->m_polys[ g ]];
1991  }
1992 */
1993  }
1994  return ( int )l_qual;
1995 }

References SkQualGrid::m_qual, m_qual_grid, and m_sim_w_div_10.

Referenced by PreProcessLandscape2().

◆ PreEvaluateHabitatStripY()

int SkTerritories::PreEvaluateHabitatStripY ( int  a_x,
int  a_y,
int  a_range_x 
)
inlineprivate
1997  {
1998  double l_qual = 0.0;
1999 
2000  int l_max_y = a_y + a_range_y;
2001  if ( l_max_y > m_sim_h_div_10 ) l_max_y = m_sim_h_div_10;
2002 
2003  for ( int y = a_y; y < l_max_y; y++ ) {
2004  int l_i = a_x + y * m_sim_w_div_10;
2005  l_qual += m_qual_grid[ l_i ]->m_qual;
2006 /*
2007  int l_gmax = (int)m_qual_grid[ l_i ]->m_polys.size();
2008  for ( int g = 0; g < l_gmax; g++ ) {
2009  l_qual += ( double )( m_qual_grid[ l_i ]->m_sizes[ g ] ) * m_qual_cache[ m_qual_grid[ l_i ]->m_polys[ g ]];
2010  }
2011 */
2012  }
2013  return ( int )l_qual;
2014 }

References SkQualGrid::m_qual, m_qual_grid, m_sim_h_div_10, and m_sim_w_div_10.

Referenced by PreProcessLandscape2().

◆ PreEvaluateQualGrid()

void SkTerritories::PreEvaluateQualGrid ( SkQualGrid a_grid,
int  a_x,
int  a_y,
int  a_width,
int  a_height 
)
private
1611  {
1612  int l_polygons = 0;
1613  double qual=0;
1614  if (a_grid->m_polys.size()==0) {
1615  for ( int y = a_y; y < a_y + a_height; y++ ) {
1616  for ( int x = a_x; x < a_x + a_width; x++ ) {
1617  int l_poly = TheLandscape->SupplyPolyRef( x, y );
1618  int l_i = m_poly_seen[ l_poly ];
1619  if ( l_i >= 0 ) {
1620  a_grid->m_sizes[ l_i ] ++;
1621  continue;
1622  }
1623  m_poly_seen[ l_poly ] = a_grid->Insert( l_poly );
1624  PolyRefData[ l_polygons++ ] = l_poly;
1625  }
1626  }
1627  for ( int i = 0; i < (int) a_grid->m_polys.size(); i++ ) {
1628  qual += ( a_grid->m_sizes[ i ] ) * m_qual_cache[ a_grid->m_polys[ i ]];
1629  m_poly_seen[ PolyRefData[ i ]] = -1; // Get ready for the next square - done here because here we know how may -1s to use
1630  }
1631  }
1632  else
1633  {
1634  for ( int i = 0; i < (int) a_grid->m_polys.size(); i++ ) {
1635  qual += ( a_grid->m_sizes[ i ] ) * m_qual_cache[ a_grid->m_polys[ i ]];
1636  }
1637  }
1638  a_grid->m_qual=qual;
1639 }
int SupplyPolyRef(int a_x, int a_y)
Definition: landscape.h:1488
vector< int > m_polys
Definition: skylarks_all.h:325
vector< int > m_sizes
Definition: skylarks_all.h:324
int Insert(int a_poly)
Definition: skylarks_all.h:328
int PolyRefData[2500]
Definition: skylarks_all.h:398

References SkQualGrid::Insert(), m_poly_seen, SkQualGrid::m_polys, SkQualGrid::m_qual, m_qual_cache, SkQualGrid::m_sizes, PolyRefData, Landscape::SupplyPolyRef(), and TheLandscape.

Referenced by PreFillQualGrid().

◆ PreFillQualCache()

void SkTerritories::PreFillQualCache ( void  )
private

This method is called only once since the male cues on returning to the landscape are thought to be structural and not vegatation based (e.g. he waits in ploughed fields). Later he will use the same assessment as the females, but this is not possible early in the season before vegetation grows.

1933  {
1939  m_qual_cache_filled = true;
1940 
1941  for ( int i = 0; i < m_sim_w_div_10 * m_sim_h_div_10; i++ ) {
1942  int l_gmax = (int)m_qual_grid[ i ]->m_polys.size();
1943  for ( int g = 0; g < l_gmax; g++ ) {
1944  int l_this_poly = m_qual_grid[ i ]->m_polys[ g ];
1945  if ( m_poly_seen[ l_this_poly ] == -1 ) {
1946  m_poly_seen[ l_this_poly ] = 1;
1947  m_qual_cache[ l_this_poly ] = PrePoly2Qual( l_this_poly );
1948  }
1949  }
1950  }
1951  for ( int i = 0; i < m_hash_size; i++ ) {
1952  m_poly_seen[ i ] = -1; // m_poly_seen is used elsewhere so is reset here.
1953  }
1954 }
bool m_qual_cache_filled
Definition: skylarks_all.h:366
int m_hash_size
Definition: skylarks_all.h:360

References m_hash_size, m_poly_seen, SkQualGrid::m_polys, m_qual_cache, m_qual_cache_filled, m_qual_grid, m_sim_h_div_10, m_sim_w_div_10, and PrePoly2Qual().

◆ PreFillQualGrid()

void SkTerritories::PreFillQualGrid ( void  )
private
1568  {
1569 // if ( m_qual_grid_signal == 2 )
1570 // return;
1571  if ( m_qual_grid_signal != 2 ){
1572  // First time we are ever called. Allocate the memory for the
1573  // quality computations, and fill in the 10x10m quality grid.
1574  m_qual_grid_signal = 2;
1576  // Using malloc because this allows us to use a test of available memory
1577  m_qual_grid = ( SkQualGrid * * ) malloc( sizeof( SkQualGrid * ) * m_sim_w_div_10 * m_sim_h_div_10 );
1578  m_poly_seen = ( int * ) malloc( sizeof( int ) * m_hash_size );
1579  m_poly_size = ( int * ) malloc( sizeof( int ) * m_hash_size );
1580  m_qual_cache = ( double * ) malloc( sizeof( double ) * m_hash_size );
1581 
1582  bool l_ok = true;
1583  for ( int i = 0; i < m_sim_w_div_10 * m_sim_h_div_10; i++ ) {
1584  m_qual_grid[ i ] = new SkQualGrid;
1585  if ( m_qual_grid[ i ] == NULL ) {
1586  l_ok = false;
1587  break;
1588  }
1589  }
1590 
1591  if ( m_qual_grid == NULL || m_poly_seen == NULL || m_qual_cache == NULL || m_poly_size == NULL || !l_ok ) {
1592  g_msg->Warn( WARN_FILE, "SkTerritories::PreFillQualGrid(): ""Out of memory!\n", "" );
1593  exit( 1 );
1594  }
1595  }
1596 
1597  for ( int i = 0; i < m_hash_size; i++ ) {
1598  m_poly_seen[ i ] = -1;
1599  }
1600 
1602  int i = 0;
1603  for ( int y = 0; y < m_sim_h_div_10; y++ ) {
1604  for ( int x = 0; x < m_sim_w_div_10; x++ ) {
1605  PreEvaluateQualGrid( m_qual_grid[ i++ ], x * 10, y * 10, 10, 10 );
1606  }
1607  }
1608  //PreFillQualCache();
1609 }
void SkylarkEvaluation(SkTerritories *a_skt)
Definition: Landscape.cpp:3025
int SupplyLargestPolyNumUsed()
Definition: landscape.h:355
Definition: skylarks_all.h:322
void PreEvaluateQualGrid(SkQualGrid *a_grid, int a_x, int a_y, int a_width, int a_height)
Definition: skylarks_all.cpp:1611

References g_land, g_msg, m_hash_size, m_poly_seen, m_poly_size, m_qual_cache, m_qual_grid, m_qual_grid_signal, m_sim_h_div_10, m_sim_w_div_10, PreEvaluateQualGrid(), Landscape::SkylarkEvaluation(), Landscape::SupplyLargestPolyNumUsed(), TheLandscape, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by PreProcessLandscape2().

◆ PreFillTerrPolyLists()

void SkTerritories::PreFillTerrPolyLists ( skTTerritory a_terr)
private
2140  {
2141  int x_min_inc = a_terr->m_x_div10;
2142  int x_max_exc = a_terr->m_x_div10 + a_terr->m_range_div10;
2143  int y_min_inc = a_terr->m_y_div10;
2144  int y_max_exc = a_terr->m_y_div10 + a_terr->m_range_div10;
2145  int l_polygons = 0;
2146 
2147  for ( int y = y_min_inc; y < y_max_exc; y++ ) {
2148  for ( int x = x_min_inc; x < x_max_exc; x++ ) {
2149  int l_i = x + y * m_sim_w_div_10;
2150  int l_gmax = (int)m_qual_grid[ l_i ]->m_polys.size();
2151  for ( int g = 0; g < l_gmax; g++ ) {
2152  int l_poly = m_qual_grid[ l_i ]->m_polys[ g ];
2153  if ( m_poly_seen[ l_poly ] == 1 ) {
2154  m_poly_size[ l_poly ] += m_qual_grid[ l_i ]->m_sizes[ g ];
2155  continue;
2156  }
2157  m_poly_seen[ l_poly ] = 1;
2158  m_poly_size[ l_poly ] = m_qual_grid[ l_i ]->m_sizes[ g ];
2159  PolyRefData[ l_polygons++ ] = l_poly;
2160  }
2161  }
2162  }
2163 
2164  a_terr->m_polys.resize( l_polygons );
2165  a_terr->m_sizes.resize( l_polygons );
2166  for ( int i = 0; i < l_polygons; i++ ) {
2167  int l_poly = PolyRefData[ i ];
2168  m_poly_seen[ l_poly ] = -1;
2169  a_terr->m_polys[ i ] = l_poly;
2170  a_terr->m_sizes[ i ] = m_poly_size[ l_poly ];
2171  }
2172 
2173  // Now build the same lists for the home range,
2174  // centered on this territory.
2175  int l_offset = ( a_terr->m_range_div10 ) >> 1;
2176  x_min_inc = a_terr->m_x_div10 + l_offset - HomeRangeDiameterDiv20;
2177  x_max_exc = a_terr->m_x_div10 + l_offset + HomeRangeDiameterDiv20;
2178  y_min_inc = a_terr->m_y_div10 + l_offset - HomeRangeDiameterDiv20;
2179  y_max_exc = a_terr->m_y_div10 + l_offset + HomeRangeDiameterDiv20;
2180 
2181  l_polygons = 0;
2182 
2183  int l_c = PreMakeForIterator( x_min_inc, x_max_exc, m_for_iter_x, m_sim_w_div_10 );
2184  PreMakeForIterator( y_min_inc, y_max_exc, m_for_iter_y, m_sim_h_div_10 );
2185 
2186  for ( int l_y = 0; l_y < l_c; l_y++ ) {
2187  int y = m_for_iter_y[ l_y ];
2188  for ( int l_x = 0; l_x < l_c; l_x++ ) {
2189  int l_i = m_for_iter_x[ l_x ] + y * m_sim_w_div_10;
2190  int l_gmax = (int)m_qual_grid[ l_i ]->m_polys.size();
2191  for ( int g = 0; g < l_gmax; g++ ) {
2192  int l_poly = m_qual_grid[ l_i ]->m_polys[ g ];
2193  if ( m_poly_seen[ l_poly ] == 1 ) {
2194  m_poly_size[ l_poly ] += m_qual_grid[ l_i ]->m_sizes[ g ];
2195  continue;
2196  }
2197  m_poly_seen[ l_poly ] = 1;
2198  m_poly_size[ l_poly ] = m_qual_grid[ l_i ]->m_sizes[ g ];
2199  PolyRefData[ l_polygons++ ] = l_poly;
2200  }
2201  }
2202  }
2203 
2204  a_terr->m_hr_polys.resize( l_polygons );
2205  a_terr->m_hr_sizes.resize( l_polygons );
2206  for ( int i = 0; i < l_polygons; i++ ) {
2207  int l_poly = PolyRefData[ i ];
2208  m_poly_seen[ l_poly ] = -1;
2209  a_terr->m_hr_polys[ i ] = l_poly;
2210  a_terr->m_hr_sizes[ i ] = m_poly_size[ l_poly ];
2211  }
2212 }
int m_for_iter_x[1000]
Definition: skylarks_all.h:368
int m_for_iter_y[1000]
Definition: skylarks_all.h:369
int PreMakeForIterator(int a_min_incl, int a_max_excl, int *a_iter, int a_norm_max_excl)
Definition: skylarks_all.cpp:2214
int m_y_div10
Definition: skylarks_all.h:271
int m_x_div10
Definition: skylarks_all.h:270
vector< int > m_hr_polys
Definition: skylarks_all.h:267
int m_range_div10
Definition: skylarks_all.h:272
vector< int > m_hr_sizes
Definition: skylarks_all.h:268
const int HomeRangeDiameterDiv20
Definition: skylarks_all.cpp:212

References HomeRangeDiameterDiv20, m_for_iter_x, m_for_iter_y, skTTerritory::m_hr_polys, skTTerritory::m_hr_sizes, m_poly_seen, m_poly_size, skTTerritory::m_polys, SkQualGrid::m_polys, m_qual_grid, skTTerritory::m_range_div10, m_sim_h_div_10, m_sim_w_div_10, skTTerritory::m_sizes, SkQualGrid::m_sizes, skTTerritory::m_x_div10, skTTerritory::m_y_div10, PolyRefData, and PreMakeForIterator().

Referenced by PreProcessLandscape2(), and Split().

◆ PreMakeForIterator()

int SkTerritories::PreMakeForIterator ( int  a_min_incl,
int  a_max_excl,
int *  a_iter,
int  a_norm_max_excl 
)
private
2214  {
2215 
2216  int i, index = 0;
2217  int med_max;
2218  int high_max = -1;
2219 
2220  if ( a_max_excl >= a_norm_max_excl ) {
2221  med_max = a_norm_max_excl;
2222  high_max = a_max_excl;
2223  } else {
2224  med_max = a_max_excl;
2225  }
2226 
2227  for ( i = a_min_incl; i < 0; i++ ) {
2228  a_iter[ index++ ] = i + a_norm_max_excl;
2229  }
2230  for ( ; i < med_max; i++ ) {
2231  a_iter[ index++ ] = i;
2232  }
2233  for ( ; i < high_max; i++ ) {
2234  a_iter[ index++ ] = i - a_norm_max_excl;
2235  }
2236  return index;
2237 }

Referenced by PreFillTerrPolyLists().

◆ PrePoly2Qual()

double SkTerritories::PrePoly2Qual ( int  a_poly)
inline

Used only on start-up when potential territories need to be determined.

1643 {
1648  double l_height;
1649  double l_score = -9999.0;
1650 // bool ppremium = false;
1651 // int l_index;
1652 
1653 
1654 
1655  switch ( l_type ) {
1656  case tole_YoungForest: //
1657  l_score = HQualityBareEarth + PatchyPremium;
1658  break;
1659  case tole_Hedges: // 130
1660  case tole_HedgeBank:
1661  l_score = HQualityHedge;
1662  break;
1663  case tole_IndividualTree:
1664  case tole_PlantNursery:
1665  case tole_WindTurbine:
1666  case tole_WoodyEnergyCrop:
1667  case tole_WoodlandMargin:
1668  case tole_Pylon:
1669  case tole_PitDisused: // 75
1670  case tole_RiversideTrees: // 97
1671  case tole_DeciduousForest: // 40
1672  case tole_MixedForest: // 60
1673  case tole_ConiferousForest: // 50
1674  case tole_ActivePit: // 115
1675  case tole_Building: // 5
1676  case tole_Copse:
1677  case tole_Orchard:
1679  l_score = HQualityTall2;
1680  break;
1681  case tole_Churchyard:
1682  case tole_Garden: //11
1683  case tole_UrbanNoVeg: // 8
1684  l_score = HQualityTallVeg;
1685  break;
1686  case tole_Saltmarsh:
1687  case tole_NaturalGrassWet:
1688  case tole_Marsh: // 95
1689  case tole_Scrub: // 70
1690  l_score = HQualityHedgeScrub;
1691  break;
1692  case tole_RoadsideSlope:
1693  case tole_Field:
1694  case tole_RoadsideVerge: // 13
1695  case tole_FieldBoundary: // 160
1697  case tole_PermanentSetaside: // 7
1698  case tole_Heath:
1701  case tole_PermPasture: // 35
1702  case tole_NaturalGrassDry: // 110
1703  case tole_BeetleBank:
1704  case tole_Wasteland:
1705  case tole_Vildtager:
1706  case tole_MownGrass:
1707  // Must be potentially suitable vegetation element so score depends on
1708  // the vegetation height
1709  l_height = TheLandscape->SupplyVegHeight( a_poly );
1710  if ( l_height >= 200.0 )
1711  {
1712  l_score = HQualityTallVeg;
1713  } else
1714  {
1715  if ( l_height >= 110.0 )
1716  {
1717  l_score = HQualityTall;
1718  } else
1719  {
1720  l_score = SKOPTIMALHABITATSCORE; // Start with a max
1721  if (!TheLandscape->SupplyVegPatchy( a_poly )) l_score *= 0.50;
1722  }
1723  }
1724  break;
1725 
1726  case tole_SmallRoad: // 120
1727  case tole_LargeRoad: // 121
1728  l_score = HQualityMetalRoad;
1729  break;
1730 
1731  case tole_MetalledPath:
1732  case tole_Carpark:
1733  case tole_Stream:
1734  case tole_HeritageSite:
1735  case tole_Pond:
1736  case tole_Freshwater: // 90
1737  case tole_FishFarm:
1738  case tole_River: // 96
1739  case tole_Saltwater: // 80
1740  case tole_Coast: // 100
1741  case tole_RiversidePlants: // 98
1742  case tole_StoneWall: // 15
1743  case tole_Fence: //225
1744  case tole_Track: // 123
1745  case tole_Railway: // 118
1746  case tole_AmenityGrass:
1747  case tole_Parkland: //14
1748  case tole_UrbanPark: //17
1749  case tole_SandDune: //101
1750  case tole_UnknownGrass:
1751  l_score = HQualityWater; // Neutral
1752  break;
1753 
1754  case tole_Foobar: // 999 !! type unknown - should not happen
1755  default:
1756  static char l_errornum[ 20 ];
1757  sprintf( l_errornum, "%d", l_type );
1758  TheLandscape->Warn( "SkTerritories::PrePoly2Qual(): ""Unknown tole_type", l_errornum );
1759  exit( 1 );
1760  break;
1761  }
1762  if (TheLandscape->SupplyVegPatchy( a_poly )) l_score += PatchyPremium;
1763  if (l_score > SKOPTIMALHABITATSCORE) l_score = SKOPTIMALHABITATSCORE;
1764  return l_score;
1765 }
bool SupplyVegPatchy(int a_polyref)
Definition: landscape.h:986
int HQualityBareEarth
Definition: skylarks_all.cpp:268
#define SKOPTIMALHABITATSCORE
Definition: skylarks_all.cpp:45
int HQualityTall
Definition: skylarks_all.cpp:255
int HQualityWater
Definition: skylarks_all.cpp:262
int HQualityHedgeScrub
Definition: skylarks_all.cpp:259
int HQualityHedge
Definition: skylarks_all.cpp:261
int PatchyPremium
Definition: skylarks_all.cpp:265
int HQualityTallVeg
Definition: skylarks_all.cpp:267
int HQualityTall2
Definition: skylarks_all.cpp:256
int HQualityMetalRoad
Definition: skylarks_all.cpp:258
TTypesOfLandscapeElement
Definition: tole_declaration.h:36
@ tole_PermPastureTussocky
Definition: tole_declaration.h:45
@ tole_Saltmarsh
Definition: tole_declaration.h:88
@ tole_WoodyEnergyCrop
Definition: tole_declaration.h:94
@ tole_Carpark
Definition: tole_declaration.h:85
@ tole_Coast
Definition: tole_declaration.h:67
@ tole_UrbanNoVeg
Definition: tole_declaration.h:78
@ tole_Stream
Definition: tole_declaration.h:89
@ tole_Saltwater
Definition: tole_declaration.h:66
@ tole_MixedForest
Definition: tole_declaration.h:53
@ tole_HeritageSite
Definition: tole_declaration.h:90
@ tole_WoodlandMargin
Definition: tole_declaration.h:98
@ tole_RoadsideSlope
Definition: tole_declaration.h:83
@ tole_River
Definition: tole_declaration.h:65
@ tole_StoneWall
Definition: tole_declaration.h:56
@ tole_Parkland
Definition: tole_declaration.h:77
@ tole_NaturalGrassWet
Definition: tole_declaration.h:87
@ tole_NaturalGrassDry
Definition: tole_declaration.h:48
@ tole_UrbanPark
Definition: tole_declaration.h:79
@ tole_Pylon
Definition: tole_declaration.h:96
@ tole_PermanentSetaside
Definition: tole_declaration.h:46
@ tole_Garden
Definition: tole_declaration.h:58
@ tole_Pond
Definition: tole_declaration.h:101
@ tole_Scrub
Definition: tole_declaration.h:42
@ tole_Fence
Definition: tole_declaration.h:57
@ tole_Copse
Definition: tole_declaration.h:82
@ tole_PermPasture
Definition: tole_declaration.h:47
@ tole_Hedges
Definition: tole_declaration.h:37
@ tole_Track
Definition: tole_declaration.h:59
@ tole_Heath
Definition: tole_declaration.h:70
@ tole_Freshwater
Definition: tole_declaration.h:64
@ tole_PitDisused
Definition: tole_declaration.h:50
@ tole_FieldBoundary
Definition: tole_declaration.h:40
@ tole_PlantNursery
Definition: tole_declaration.h:95
@ tole_DeciduousForest
Definition: tole_declaration.h:52
@ tole_ActivePit
Definition: tole_declaration.h:63
@ tole_RiversidePlants
Definition: tole_declaration.h:49
@ tole_Building
Definition: tole_declaration.h:62
@ tole_RoadsideVerge
Definition: tole_declaration.h:38
@ tole_Vildtager
Definition: tole_declaration.h:99
@ tole_Orchard
Definition: tole_declaration.h:71
@ tole_MownGrass
Definition: tole_declaration.h:74
@ tole_YoungForest
Definition: tole_declaration.h:55
@ tole_SmallRoad
Definition: tole_declaration.h:60
@ tole_Churchyard
Definition: tole_declaration.h:86
@ tole_BuiltUpWithParkland
Definition: tole_declaration.h:80
@ tole_AmenityGrass
Definition: tole_declaration.h:76
@ tole_PermPastureLowYield
Definition: tole_declaration.h:44
@ tole_HedgeBank
Definition: tole_declaration.h:68
@ tole_Railway
Definition: tole_declaration.h:39
@ tole_WindTurbine
Definition: tole_declaration.h:97
@ tole_ConiferousForest
Definition: tole_declaration.h:54
@ tole_SandDune
Definition: tole_declaration.h:81
@ tole_Wasteland
Definition: tole_declaration.h:92
@ tole_IndividualTree
Definition: tole_declaration.h:93
@ tole_UnknownGrass
Definition: tole_declaration.h:91
@ tole_Foobar
Definition: tole_declaration.h:111
@ tole_RiversideTrees
Definition: tole_declaration.h:51
@ tole_LargeRoad
Definition: tole_declaration.h:61
@ tole_UnsprayedFieldMargin
Definition: tole_declaration.h:72
@ tole_BeetleBank
Definition: tole_declaration.h:69
@ tole_MetalledPath
Definition: tole_declaration.h:84
@ tole_FishFarm
Definition: tole_declaration.h:102
@ tole_Marsh
Definition: tole_declaration.h:41

References HQualityBareEarth, HQualityHedge, HQualityHedgeScrub, HQualityMetalRoad, HQualityTall, HQualityTall2, HQualityTallVeg, HQualityWater, PatchyPremium, SKOPTIMALHABITATSCORE, Landscape::SupplyElementType(), Landscape::SupplyVegHeight(), Landscape::SupplyVegPatchy(), TheLandscape, tole_ActivePit, tole_AmenityGrass, tole_BeetleBank, tole_Building, tole_BuiltUpWithParkland, tole_Carpark, tole_Churchyard, tole_Coast, tole_ConiferousForest, tole_Copse, tole_DeciduousForest, tole_Fence, tole_Field, tole_FieldBoundary, tole_FishFarm, tole_Foobar, tole_Freshwater, tole_Garden, tole_Heath, tole_HedgeBank, tole_Hedges, tole_HeritageSite, tole_IndividualTree, tole_LargeRoad, tole_Marsh, tole_MetalledPath, tole_MixedForest, tole_MownGrass, tole_NaturalGrassDry, tole_NaturalGrassWet, tole_Orchard, tole_Parkland, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, tole_PitDisused, tole_PlantNursery, tole_Pond, tole_Pylon, tole_Railway, tole_River, tole_RiversidePlants, tole_RiversideTrees, tole_RoadsideSlope, tole_RoadsideVerge, tole_Saltmarsh, tole_Saltwater, tole_SandDune, tole_Scrub, tole_SmallRoad, tole_StoneWall, tole_Stream, tole_Track, tole_UnknownGrass, tole_UnsprayedFieldMargin, tole_UrbanNoVeg, tole_UrbanPark, tole_Vildtager, tole_Wasteland, tole_WindTurbine, tole_WoodlandMargin, tole_WoodyEnergyCrop, tole_YoungForest, and Landscape::Warn().

Referenced by PreCachePoly(), and PreFillQualCache().

◆ PrePolyNQual()

double SkTerritories::PrePolyNQual ( int  a_poly,
int *  a_good_polys 
)
inline
1768  {
1770  double l_height;
1771  double l_score = -9999.0;
1772  bool ppremium = false;
1773 // int l_index;
1774 
1775 
1776 
1777  switch ( l_type ) {
1778  case tole_YoungForest: //
1779  l_score = HQualityBareEarth + PatchyPremium;
1780  break;
1781  case tole_Hedges: // 130
1782  case tole_HedgeBank:
1783  l_score = HQualityHedge;
1784  break;
1785  case tole_IndividualTree:
1786  case tole_PlantNursery:
1787  case tole_WindTurbine:
1788  case tole_WoodyEnergyCrop:
1789  case tole_WoodlandMargin:
1790  case tole_Pylon:
1791  case tole_PitDisused: // 75
1792  case tole_RiversideTrees: // 97
1793  case tole_DeciduousForest: // 40
1794  case tole_MixedForest: // 60
1795  case tole_ConiferousForest: // 50
1796  case tole_ActivePit: // 115
1797  case tole_Building: // 5
1798  case tole_Copse:
1799  case tole_Orchard:
1801  l_score = HQualityTall2;
1802  break;
1803  case tole_Churchyard:
1804  case tole_Garden: //11
1805  case tole_UrbanNoVeg: // 8
1806  l_score = HQualityTallVeg;
1807  break;
1808  case tole_NaturalGrassWet:
1809  case tole_Saltmarsh:
1810  case tole_Marsh: // 95
1811  case tole_Scrub: // 70
1812  l_score = HQualityHedgeScrub;
1813  break;
1814  case tole_RoadsideSlope:
1815  case tole_Field:
1816  case tole_RoadsideVerge: // 13
1817  case tole_FieldBoundary: // 160
1819  case tole_PermanentSetaside: // 7
1820  case tole_Heath:
1823  case tole_PermPasture: // 35
1824  case tole_NaturalGrassDry: // 110
1825  case tole_BeetleBank:
1826  case tole_Wasteland:
1827  case tole_Vildtager:
1828  case tole_MownGrass:
1829  // Must be potentially suitable vegetation element so score depends on
1830  // the vegetation height
1831  l_height = TheLandscape->SupplyVegHeight( a_poly );
1832  ppremium = TheLandscape->SupplyVegPatchy( a_poly );
1833  // If using skylark scrapes then we need the code below
1834  if ( TheLandscape->SupplySkScrapes(a_poly) && (l_height >=30) )
1835  {
1836  if ( l_height >= 200.0 )
1837  {
1838  l_score = HQualityTallVeg;
1839  } else
1840  {
1841  if ( l_height >= 110.0 )
1842  {
1843  l_score = HQualityTall;
1844  }
1845  else if ( l_height < 3.0 )
1846  {
1847  l_score = HQualityBareEarth;
1848  } else
1849  {
1850  l_score = SKOPTIMALHABITATSCORE / 2.0; // Start with standard (less some to allow for doubling territory)
1851  double hh;
1852  if (l_height>70) hh = 70; else hh = l_height;
1853  l_score += hh * cfg_SkScrapesPremiumII.value();
1854  int density = TheLandscape->SupplyVegDensity( a_poly );
1855  l_score += ( DensityScore[ density ] + HeightScore[ ( int )l_height ] );
1856  }
1857  }
1858  }
1859  else
1860  {
1861  // No skylark scrapes
1862  if ( l_height >= 200.0 )
1863  {
1864  l_score = HQualityTallVeg;
1865  } else
1866  {
1867  if ( l_height >= 110.0 )
1868  {
1869  l_score = HQualityTall;
1870  if ( ppremium ) l_score += PatchyPremium;
1871  }
1872  else if ( l_height < 3.0 )
1873  {
1874  l_score = HQualityBareEarth;
1875  } else
1876  {
1877  l_score = SKOPTIMALHABITATSCORE / 2.0; // Start with half standard - less some to allow doubling (taken up in the minimum territory accept score)
1878  int density;
1879  if (l_height<=30) density = 0; else density = TheLandscape->SupplyVegDensity( a_poly );
1880  l_score += ( DensityScore[ density ] + HeightScore[ ( int )l_height ] );
1881  if ( ppremium ) l_score += PatchyPremium;
1882  else
1883  {
1884  if ( TheLandscape->SupplyHasTramlines( a_poly )) l_score += cfg_SkTramlinesPremium.value();
1885  }
1886  }
1887  }
1888  }
1889  break;
1890 
1891  case tole_SmallRoad: // 120
1892  case tole_LargeRoad: // 121
1893  l_score = HQualityMetalRoad;
1894  break;
1895 
1896  case tole_MetalledPath:
1897  case tole_Carpark:
1898  case tole_Stream:
1899  case tole_HeritageSite:
1900  case tole_Pond:
1901  case tole_Freshwater: // 90
1902  case tole_FishFarm:
1903  case tole_River: // 96
1904  case tole_Saltwater: // 80
1905  case tole_Coast: // 100
1906  case tole_RiversidePlants: // 98
1907  case tole_StoneWall: // 15
1908  case tole_Fence:
1909  case tole_Track: // 123
1910  case tole_Railway: // 118
1911  case tole_AmenityGrass:
1912  case tole_Parkland: //14
1913  case tole_UrbanPark: //17
1914  case tole_SandDune: //101
1915  case tole_UnknownGrass:
1916  l_score = HQualityWater; // Neutral
1917  break;
1918 
1919  case tole_Foobar: // 999 !! type unknown - should not happen
1920  default:
1921  static char l_errornum[ 20 ];
1922  sprintf( l_errornum, "%d", l_type );
1923  TheLandscape->Warn( "SkTerritories::PrePolyNQual(): ""Unknown tole_type", l_errornum );
1924  exit( 1 );
1925  break;
1926  }
1927  if (l_score > SKOPTIMALHABITATSCORE) l_score = SKOPTIMALHABITATSCORE;
1928  return l_score;
1929 }
double value(void)
Definition: configurator.h:118
int value(void)
Definition: configurator.h:98
int SupplyVegDensity(int a_polyref)
Definition: landscape.h:975
bool SupplySkScrapes(int a_polyref)
Definition: landscape.h:981
bool SupplyHasTramlines(int a_x, int a_y)
Definition: landscape.h:1252
double HeightScore[111]
Definition: skylarks_all.cpp:219
double DensityScore[111]
Definition: skylarks_all.cpp:218
CfgInt cfg_SkTramlinesPremium
CfgFloat cfg_SkScrapesPremiumII

References cfg_SkScrapesPremiumII, cfg_SkTramlinesPremium, DensityScore, HeightScore, HQualityBareEarth, HQualityHedge, HQualityHedgeScrub, HQualityMetalRoad, HQualityTall, HQualityTall2, HQualityTallVeg, HQualityWater, PatchyPremium, SKOPTIMALHABITATSCORE, Landscape::SupplyElementType(), Landscape::SupplyHasTramlines(), Landscape::SupplySkScrapes(), Landscape::SupplyVegDensity(), Landscape::SupplyVegHeight(), Landscape::SupplyVegPatchy(), TheLandscape, tole_ActivePit, tole_AmenityGrass, tole_BeetleBank, tole_Building, tole_BuiltUpWithParkland, tole_Carpark, tole_Churchyard, tole_Coast, tole_ConiferousForest, tole_Copse, tole_DeciduousForest, tole_Fence, tole_Field, tole_FieldBoundary, tole_FishFarm, tole_Foobar, tole_Freshwater, tole_Garden, tole_Heath, tole_HedgeBank, tole_Hedges, tole_HeritageSite, tole_IndividualTree, tole_LargeRoad, tole_Marsh, tole_MetalledPath, tole_MixedForest, tole_MownGrass, tole_NaturalGrassDry, tole_NaturalGrassWet, tole_Orchard, tole_Parkland, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, tole_PitDisused, tole_PlantNursery, tole_Pond, tole_Pylon, tole_Railway, tole_River, tole_RiversidePlants, tole_RiversideTrees, tole_RoadsideSlope, tole_RoadsideVerge, tole_Saltmarsh, tole_Saltwater, tole_SandDune, tole_Scrub, tole_SmallRoad, tole_StoneWall, tole_Stream, tole_Track, tole_UnknownGrass, tole_UnsprayedFieldMargin, tole_UrbanNoVeg, tole_UrbanPark, tole_Vildtager, tole_Wasteland, tole_WindTurbine, tole_WoodlandMargin, tole_WoodyEnergyCrop, tole_YoungForest, CfgInt::value(), CfgFloat::value(), and Landscape::Warn().

Referenced by EvaluateHabitatN().

◆ PreProcessLandscape2()

void SkTerritories::PreProcessLandscape2 ( Landscape L)
2016  {
2017  //time_t l_time = time( NULL );
2018  //printf("%s\n", asctime(localtime(&l_time)));
2019 
2020  // if this is not the first year then delete the old territories
2021  for ( int i = 0; i < NoTerritories; i++ )
2022  delete Territories[ i ];
2023  NoTerritories = 0;
2024 
2025  PreFillQualGrid();
2026 
2027  // Zero all Grid Positions
2028  for ( int i = 0; i < m_sim_w_div_10; i++ )
2029  for ( int j = 0; j < m_sim_h_div_10; j++ )
2030  Grid[i + j * m_sim_w_div_10] = false;
2031 
2032  int x = random( m_sim_w_div_10 ); // was 3
2033  int y = random( m_sim_h_div_10 ); // was 0
2034  int qual;
2035  int range = 5; // Start with a 50m territory
2036  // Next start the loop
2037  int tries = m_sim_w_div_10 * m_sim_h_div_10;
2038 
2039  while ( tries-- ) {
2040  int targetqual = (int) (cfg_FemaleMinTerritoryAcceptScore.value() * (0.9 + g_rand_uni()/5.0));
2041  if ( !IsGridPositionValid( x, y, range ) ) {
2042  if ( ++x >= m_sim_w_div_10 ) {
2043  x = random( 3 );
2044  if ( ++y >= m_sim_h_div_10 ) {
2045  y = 0;
2046  }
2047  }
2048  continue;
2049  }
2050 
2051  // Location was OK, ie. not occupied.
2052 
2053  // Try the smallest possible territory located right at our starting
2054  // position.
2055  qual = PreEvaluateHabitat( x, y, range, range );
2056 
2057  // Is it suitable?
2058  if ( qual >= targetqual ) {
2059  // If so create it and claim the area on the grid
2060  // Is OK so create a territory
2061  if ( NoTerritories > 199999 ) {
2062  static char errornum[ 20 ];
2063  sprintf( errornum, "%d", NoTerritories );
2064  L->Warn( "SkTerritories::PreProcessLandscape2(): ""Too many territories!", errornum );
2065  exit( 1 );
2066  }
2067  Territories[ NoTerritories ] = new skTTerritory( x * 10, y * 10, range * 10, qual, x, y, range ); // Here we have some variation in the quality requirements
2069  // Build the per-territory lists of poygons and associated
2070  // areas.
2072 
2073  // Claim the territory in the grid
2074  ClaimGrid( x, y, range );
2075  x += range - 1;
2076  range = 5;
2077  continue;
2078  }
2079 
2080  // Not suitable too low quality, but can increase the area
2081  bool done = false;
2082  bool success = false;
2083  do {
2084  if ( ++range > 28 ) {
2085  // Max. allowed territory size is 280m square.
2086  done = true;
2087  } else {
2088  if ( IsExtGridPositionValid( x, y, range ) ) {
2089  // Check Quality
2090  // No point in rechecking the area already checked so just
2091  // check the new area
2092  qual += PreEvaluateHabitatStripX( x, y + range - 1, range );
2093  qual += PreEvaluateHabitatStripY( x + range - 1, y, range );
2094  //qual= PreEvaluateHabitat( x, y, range, range );
2095  if ( qual >= targetqual ) {
2096  // If so create it and claim the area on the grid
2097  // Is OK so create a territory
2098  if ( NoTerritories < 0 || NoTerritories > 199999 ) {
2099  static char errornum[ 20 ];
2100  sprintf( errornum, "%d", NoTerritories );
2101  L->Warn( "SkTerritories::PreProcessLandscape2():"" Too many territories!", errornum );
2102  exit( 0 );
2103  }
2104  success = true;
2105  done = true;
2106  Territories[ NoTerritories ] = new skTTerritory( x * 10, y * 10, range * 10, qual, x, y, range );
2108  // Build the per-territory lists of poygons and associated
2109  // areas.
2111  ClaimGrid( x, y, range );
2112  x += range - 1;
2113  range = 5;
2114  }
2115  }
2116  }
2117  } while ( !done );
2118 
2119  if ( !success ) {
2120  Grid[x + y * m_sim_w_div_10] = true;
2121  if ( ++x >= m_sim_w_div_10 ) {
2122  // Next line down
2123  x = random( 3 );
2124  if ( ++y >= m_sim_h_div_10 ) {
2125  y = 0;
2126  }
2127  }
2128  range = 5;
2129  }
2130  }
2131  if (NoTerritories < 1) {
2132  static char errornum[20];
2133  sprintf(errornum, "%d", NoTerritories);
2134  L->Warn("SkTerritories::PreProcessLandscape2(): ""Not enough territories! ", errornum);
2135  exit(1);
2136  }
2137  }
int random(int a_range)
Definition: ALMaSS_CmdLine.cpp:142
bool IsGridPositionValid(int &x, int &y, int range)
Definition: skylarks_all.cpp:2272
bool IsExtGridPositionValid(int &x, int &y, int range)
Definition: skylarks_all.cpp:2296
int PreEvaluateHabitatStripX(int a_x, int a_y, int a_range_x)
Definition: skylarks_all.cpp:1976
int PreEvaluateHabitatStripY(int a_x, int a_y, int a_range_x)
Definition: skylarks_all.cpp:1997
void PreFillQualGrid(void)
Definition: skylarks_all.cpp:1568
int PreEvaluateHabitat(int a_x, int a_y, int a_range_x, int a_range_y)
Definition: skylarks_all.cpp:1957
void ClaimGrid(int x, int y, int range)
Definition: skylarks_all.cpp:2331
void PreFillTerrPolyLists(skTTerritory *a_terr)
Definition: skylarks_all.cpp:2140
Definition: skylarks_all.h:263
void TestNestPossibility()
Definition: skylarks_all.cpp:1292
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
CfgFloat cfg_FemaleMinTerritoryAcceptScore

References cfg_FemaleMinTerritoryAcceptScore, ClaimGrid(), g_rand_uni, Grid, IsExtGridPositionValid(), IsGridPositionValid(), m_sim_h_div_10, m_sim_w_div_10, NoTerritories, PreEvaluateHabitat(), PreEvaluateHabitatStripX(), PreEvaluateHabitatStripY(), PreFillQualGrid(), PreFillTerrPolyLists(), random(), Territories, skTTerritory::TestNestPossibility(), CfgFloat::value(), and Landscape::Warn().

Referenced by Skylark_Population_Manager::DoFirst().

◆ RemoveFemale()

void SkTerritories::RemoveFemale ( int  ref)

◆ RemoveMale()

void SkTerritories::RemoveMale ( int  ref)

◆ Split()

void SkTerritories::Split ( int  ref)

Duplicates the old territory.

Reduces the virtual size.

2413  {
2415  Territories[ NoTerritories++ ] = new skTTerritory( Territories[ ref]->m_Location_x, Territories[ ref]->m_Location_y,
2416  Territories[ ref ]->Size, Territories[ ref ]->GetQuality(), Territories[ ref ]->m_x_div10, Territories[ ref ]->m_y_div10,
2417  Territories[ ref ]->m_range_div10 );
2419  Territories[ NoTerritories-1 ]->SetNestPossibility(Territories[ ref]->m_nest_valid,Territories[ ref]->m_nest_pos_validx,Territories[ ref]->m_nest_pos_validy);
2423  double Vdir=Territories[ ref]->GetVirtualDiameter()/1.41; // 1.41 is the theoretical diameter scale when dividing one territory into two
2424  Territories[ ref]->SetVirtualDiameter(Vdir);
2426  //printf("New %d\t%d\n",g_land->SupplyDayInYear(),NoTerritories);
2427 }
double GetVirtualDiameter()
Definition: skylarks_all.h:277
void SetVirtualDiameter(double dia)
Definition: skylarks_all.h:278
void SetNestPossibility(bool valid, int nx, int ny)
Definition: skylarks_all.h:291
CfgFloat cfg_MaleSplitScale

References cfg_MaleSplitScale, skTTerritory::GetVirtualDiameter(), skTTerritory::m_competitionscaler, NoTerritories, PreFillTerrPolyLists(), skTTerritory::SetNestPossibility(), skTTerritory::SetVirtualDiameter(), Territories, and CfgFloat::value().

Referenced by Skylark_Male::ReEvaluateTerritory().

◆ Supply_F_Owner()

Skylark_Female * SkTerritories::Supply_F_Owner ( int  ref)
1459  {
1460  return Territories[ ref ]->F_Owner;
1461 }

References skTTerritory::F_Owner, and Territories.

Referenced by Skylark_Female::st_Finding_Territory().

◆ Supply_Owner()

Skylark_Male * SkTerritories::Supply_Owner ( int  ref)

◆ Supply_quality()

int SkTerritories::Supply_quality ( int  ref)
2379  {
2380  return Territories[ ref ]->GetQuality();
2381 }
int GetQuality(void)
Definition: skylarks_all.h:284

References skTTerritory::GetQuality(), and Territories.

Referenced by Skylark_Male::st_FindingTerritory(), and Skylark_Population_Manager::TheSkylarkTerrsSupply_quality().

◆ Supply_size()

int SkTerritories::Supply_size ( int  ref)

◆ Supply_terr()

skTTerritory * SkTerritories::Supply_terr ( int  ref)

◆ Supply_x()

int SkTerritories::Supply_x ( int  ref)

◆ Supply_y()

int SkTerritories::Supply_y ( int  ref)

◆ SupplyIsNestValid()

bool SkTerritories::SupplyIsNestValid ( int  ref)
inline
426  {
427  return Territories[ref]->m_nest_valid;
428  }
bool m_nest_valid
Definition: skylarks_all.h:273

References skTTerritory::m_nest_valid.

Referenced by Skylark_Male::OnReHouse(), and Skylark_Male::st_FindingTerritory().

◆ SupplyNestPosition()

APoint SkTerritories::SupplyNestPosition ( int  ref)
inline
429  {
430  APoint p(Territories[ref]->m_nest_pos_validx, Territories[ref]->m_nest_pos_validy);
431  return p;
432  }

◆ SupplyNoFemaleOccupied()

int SkTerritories::SupplyNoFemaleOccupied ( )
1439  {
1440  int no=0;
1441  for (int i=0; i<NoTerritories; i++) {
1442  if (Territories[i]->F_Owner != NULL) no++;
1443  }
1444  return no;
1445 }

References NoTerritories, and Territories.

◆ SupplyNoMaleOccupied()

int SkTerritories::SupplyNoMaleOccupied ( )
1429  {
1430  int no=0;
1431  for (int i=0; i<NoTerritories; i++) {
1432  if (Territories[i]->Owner != NULL) no++;
1433  }
1434  return no;
1435 }

References NoTerritories, and Territories.

◆ SupplyNoTerritories()

int SkTerritories::SupplyNoTerritories ( )

◆ Tick()

void SkTerritories::Tick ( void  )
inline
391  {
392  m_qual_cache_filled = false;
393  }

Referenced by Skylark_Population_Manager::DoFirst().

◆ UpdateQuality()

void SkTerritories::UpdateQuality ( )

Member Data Documentation

◆ Grid

bool* SkTerritories::Grid
private

◆ m_for_iter_x

int SkTerritories::m_for_iter_x[1000]
private

Referenced by PreFillTerrPolyLists().

◆ m_for_iter_y

int SkTerritories::m_for_iter_y[1000]
private

Referenced by PreFillTerrPolyLists().

◆ m_hash_size

int SkTerritories::m_hash_size
private

◆ m_poly_seen

int* SkTerritories::m_poly_seen
private

◆ m_poly_size

int* SkTerritories::m_poly_size
private

◆ m_qual_cache

double* SkTerritories::m_qual_cache
private

◆ m_qual_cache_filled

bool SkTerritories::m_qual_cache_filled
private

Referenced by PreFillQualCache().

◆ m_qual_grid

◆ m_qual_grid_signal

int SkTerritories::m_qual_grid_signal
private

Referenced by PreFillQualGrid(), and SkTerritories().

◆ m_sim_h_div_10

◆ m_sim_w_div_10

◆ NoTerritories

◆ PolyHeightData

double SkTerritories::PolyHeightData[2500]

◆ PolyRefData

int SkTerritories::PolyRefData[2500]

◆ PolySizeData

int SkTerritories::PolySizeData[2500]

◆ PolyTypeData

TTypesOfLandscapeElement SkTerritories::PolyTypeData[2500]

◆ SimH

int SkTerritories::SimH
private

Referenced by SkTerritories().

◆ SimW

int SkTerritories::SimW
private

Referenced by SkTerritories().

◆ Territories

◆ TheLandscape


The documentation for this class was generated from the following files: